/**
 * Created by Admin on 2018/1/4.
 */
define(function (require, exports, module) {
    var template = require("template");
    var loadingTpl = require("../common/tpl/loading.html");
    var tpl = require("./tpl/statisticReportTpl.html");
    require("../common/dialog");


    var List = {
        bindEvent:function(){
            var self = this;
            $("body").on("click",".btnDownload",function(){
                window.location.href=window.jkconfig.webapiurlv+"report/download?fileurl="+$(this).attr("data-fileUrl")+"&"+api_key+"="+token;
            }).on("click",".btn_staticSearch",function(){
                self.init();
            }).on("click",".btnGenerate",function(){
               $.ajax({
                   url:window.jkconfig.webapiurlv + "report/generate",
                   success:function(data){
                       var day = new Date();
                       if(data.code == 0){
                           $.showConfirm("您确定生成"+day.getFullYear()+"-"+(day.getMonth()+1)+"-"+day.getDate()+"的报表吗?",function(){
                               $.showSuccessTimeout("报表生成需要一段时间,请您隔一段时间重新刷新页面查看!",function(){
                                   window.parent.location.reload();
                               });
                           })
                       }
                   }
               })
            })
        },
        init:function(){
            $("#staticReport").html(template.compile(loadingTpl));
            $.ajax({
                url:window.jkconfig.webapiurlv+"report/list?title="+$("[name=title]").val(),
                success:function(data){
                    if(data.code==0){
                        $(".la-square-jelly-box.la-2x").hide();
                        var html = template.compile(tpl)({data:data.list});
                        $("#staticReport").html(html);
                    }else{
                        $("#staticReport").html("<div class='nodata-title'>对不起，暂无数据!</div>");
                    }
                }
            })
        },
    }
    List.init();
    List.bindEvent();




})